package com.waqu.common.utils.waqu;

import com.waqu.common.utils.text.StringTools;
import java.util.Collection;
import java.util.Map;
import com.waqu.common.utils.collection.ArrayMapTools;

/**
 * @Title SrchQudanTools.java
 * @Package com.waqu.common.utils.text
 * @author shaolianjie
 */
public class SrchQudanTools {

	private final static String SRCH_QDID_PREFIX = "srch_";

	public final static String genQdidByQuery(String query) {
		if (query == null) {
			return null;
		}
		return SRCH_QDID_PREFIX + StringTools.trim(query).hashCode();
	}

	public final static boolean checkIsQueryQudan(String qdid) {
		return StringTools.startsWith(qdid, SRCH_QDID_PREFIX);
	}

	/** 将qdids按是否是搜索趣单分类，填充queryQdids和cmsQdids */
	static public void splitQueryQdidAndCmsQdid(Collection<String> qdids, 
			final Collection<String> queryQdids, final Collection<String> cmsQdids)
	{
		if (ArrayMapTools.isEmpty(qdids))
			return;
		
		qdids.forEach(qdid -> {
			if (SrchQudanTools.checkIsQueryQudan(qdid))
				queryQdids.add(qdid);
			else
				cmsQdids.add(qdid);
		});
	}

	/** 将qdids按是否是搜索趣单分类，填充queryQdids和cmsQdids */
	static public <T> void splitQueryQdidAndCmsQdid(Map<String, T> qdids, 
			final Map<String, T> queryQdids, final Map<String, T> cmsQdids)
	{
		if (ArrayMapTools.isEmpty(qdids))
			return;
		
		qdids.forEach((qdid, v) -> {
			if (SrchQudanTools.checkIsQueryQudan(qdid))
				queryQdids.put(qdid, v);
			else
				cmsQdids.put(qdid, v);
		});
	}
}
